package com.zuihai.app.mvp.ui.holder;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.base.BaseApplication;
import com.jess.arms.utils.KnifeUtil;
import com.jess.arms.widget.imageloader.ImageLoader;
import com.jess.arms.widget.imageloader.glide.GlideImageConfig;
import com.zuihai.app.R;
import com.zuihai.app.mvp.ui.utils.MyUtils;

/**
 * Created by Administrator on 2017/5/20 0020.
 */

public class BaseViewHolderWraper<T> extends BaseViewHolder {

    protected BaseApplication mApplication;
    protected ImageLoader mImageLoader;

    public BaseViewHolderWraper(View view) {
        super(view);
        KnifeUtil.bindTarget(this, view);
        mApplication = (BaseApplication) itemView.getContext().getApplicationContext();
        mImageLoader = mApplication.getAppComponent().imageLoader();
    }

    /**
     * 加载网络图片
     *
     * @param url
     * @param target
     */
    public void loadImage(int target, String url) {
        if (!TextUtils.isEmpty(url)) {
            mImageLoader.loadImage(mApplication, GlideImageConfig
                    .builder()
                    .url(url)
                    .imageView(getView(target))
                    .errorPic(R.mipmap.img_portrait)
                    .placeholder(R.mipmap.img_portrait)
                    .build());
        }
    }
    /**
     * 加载网络图片
     *
     * @param url
     * @param target
     */
    public void loadImage32(int target, String url) {
        if (!TextUtils.isEmpty(url)) {
            mImageLoader.loadImage(mApplication, GlideImageConfig
                    .builder()
                    .url(url)
                    .imageView(getView(target))
                    .errorPic(R.mipmap.position_rectangle_small)
                    .placeholder(R.mipmap.position_rectangle_small)
                    .build());
        }
    }

    /**
     * 加载网络图片
     *
     * @param url
     * @param target
     */
    public void loadImageBig(int target, String url) {
        if (!TextUtils.isEmpty(url)) {
            mImageLoader.loadImage(mApplication, GlideImageConfig
                    .builder()
                    .url(url)
                    .imageView(getView(target))
                    .errorPic(R.mipmap.position_rectangle_big)
                    .placeholder(R.mipmap.position_rectangle_big)
                    .build());
        }
    }
    /**
     * 加载网络图片
     *
     * @param url
     * @param target
     */
    public void loadImage169(int target, String url) {
        if (!TextUtils.isEmpty(url)) {
            mImageLoader.loadImage(mApplication, GlideImageConfig
                    .builder()
                    .url(url)
                    .imageView(getView(target))
                    .errorPic(R.mipmap.position_rectangle_big)
                    .placeholder(R.mipmap.position_rectangle_big)
                    .build());
        }
    }

    public void loadGlideImage(ImageView target, String url){
        MyUtils.enlargeGlide(mApplication,url,target);
    };

    /**
     * 加载头像图片
     *
     * @param url
     * @param target
     */
    public void loadHeadImage(int target, String url) {
        if (!TextUtils.isEmpty(url)) {
            mImageLoader.loadImage(mApplication, GlideImageConfig
                    .builder()
                    .url(url)
                    .imageView(getView(target))
                    .errorPic(R.mipmap.tab_complete)
                    .placeholder(R.mipmap.tab_complete)
                    .build());
        }
    }

    public void setTextFormat(int target, Object str) {
        TextView textView = getView(target);
        textView.setText(String.format(textView.getText().toString(), str));
    }

    /**
     * 填充内容
     *
     * @param data
     * @param position
     */
    public void fillData(T data, int position) {
    }
}
